package com.misty.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.misty.blog.service.MessageService;
import com.misty.common.bean.Result;
import com.misty.common.constants.ResultEnum;
import com.misty.dao.domain.Message;
import com.misty.dao.dto.MessageDto;
import com.misty.dao.mapper.MessageMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cthulhu
 * @since 2022-11-21
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {

    @Resource
    private MessageMapper messageMapper;

    /**
     *
     * @Param
     * @return
     * @Description 分页查询回复
     * @Date
     **/
    @Override
    public Result<?> selectMessagePage(Integer pageNum, Integer pageSize, Integer commentId) {
        LambdaQueryWrapper<Message> messageLambdaQueryWrapper = Wrappers.<Message>lambdaQuery();
        if(commentId != null){
            messageLambdaQueryWrapper.eq(Message::getCommentId, commentId);
        }
        Page<MessageDto> messagePage = messageMapper.selectPageWithUser(new Page<>(pageNum, pageSize),messageLambdaQueryWrapper);
        if(messagePage.getTotal() <= 0){
            Result.error("分页查询回复失败！");
        }
        return Result.success("分页查询回复成功！",messagePage);
    }

}
